<?php

$this->pageHeader = t('PAGE_HEADER_CREATE', 'menu');
$this->pageTitle = t('PAGE_TITLE', 'menu');
$toolbar = new LGToolbar();
$toolbar->ButtonSave(t('BTN_SAVE'), '#menu-form', ActionType::SAVE);
$toolbar->ButtonSave(t('BTN_SAVE_AND_CLOSE', 'article'), '#menu-form', ActionType::SAVE_CLOSE);
$toolbar->ButtonSave(t('BTN_SAVE_AND_NEW', 'article'), '#menu-form', ActionType::SAVE_NEW);
$toolbar->Cancel('btnCancel', t('BTN_CANCEL'));
$this->pageToolbar = $toolbar->mergeToolbar();
$this->breadcrumbs = array(t('MENU_MANAGEMENT'), t('LBL_MENU_TYPE', 'menuType') => url('menutype'), 'Menu Item' => array('index'));
?>

<?php

//Load deafult menu_type_id
$stateMenu = Yii::app()->user->getState(app()->controller->id . MenuController::MODEL_CLASS_NAME);
if (!isset($model->menu_type_id) && isset($stateMenu['menu_type_id'])) {
    $model->menu_type_id = $stateMenu['menu_type_id'];
}

if ($model->extension != NULL) {
    if ($model->extension->view == LGConstant::EXTENSION_VIEW_CATEGORY_BLOG) {
	$arr = CJSON::decode($model->param);
	if ($arr != NULL) {
	    $model->categoryId = $arr['id'];
	}
    } else if ($model->extension->view == LGConstant::EXTENSION_VIEW_SINGLE_ARTICLE) {
	$arr = CJSON::decode($model->param);
	if ($arr != NULL) {
	    $article = Article::model()->find('id=?', array($arr['id']));
	    if ($article) {
		$model->article = $article->title;
	    }
	}
    } else if ($model->extension->view == LGConstant::EXTENSION_VIEW_EXTERNAL_LINK) {
	$model->external_link = $model->link;
    } else if ($model->extension->view == LGConstant::EXTENSION_VIEW_GALLERY_ITEM) {
	$arr = CJSON::decode($model->param);
	if ($arr != NULL) {
	    $model->album_id = $arr['id'];
	}
    }
}
echo $this->renderPartial('_form', array('model' => $model), false, true);
?>